﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;

namespace DTO
{
    public class News
    {
        int id;
        int type;
        String user1;
        String user2;
        DateTime time;
        String summary;
        String link;
        Boolean isRead;

        public News()
        {
        }

        /// <summary>
        /// News ID.
        /// </summary>
        public int ID
        {
            get { return this.id; }
        }

        /// <summary>
        /// Type of News.
        /// </summary>
        ///    /// <summary>
        /// Create DTO.User instance using SqlDataReader object.
        /// </summary>
        /// <param name="reader">Object contains informations get from DB.</param>
        public News(SqlDataReader reader)
        {
            if (reader != null && !reader.IsClosed)
            {
                id = reader.GetInt32(0);
                user1 = reader.GetString(1);
                user2 = reader.GetString(2);
                type = reader.GetInt32(3);
               link = reader.GetString(4);
                summary = reader.GetString(5);
                time = reader.GetDateTime(6);
                          
            }
        }
        public int Type
        {
            get { return this.type; }
            set { this.type = value; }
        }

        /// <summary>
        /// The user who is the main person in this news.
        /// </summary>
        public String User1ID
        {
            get { return this.user1; }
            set 
            {
                if (value == null || "".Equals(value))
                    throw new Exception("ID of the user1 is null.");
                else
                    this.user1 = value;
            }
        }

        /// <summary>
        /// The user who has some involkes with this news.
        /// </summary>
        public String User2ID
        {
            get { return this.user2; }
            set { this.user2 = value; }
        }

        /// <summary>
        /// Show whether this News is read or not.
        /// </summary>
        public Boolean IsRead
        {
            get { return this.isRead; }
            set { this.isRead = value; }
        }

        /// <summary>
        /// The time when this news is made.
        /// </summary>
        public DateTime Time
        {
            get { return this.time; }
            set
            {
                if (value == null)
                    throw new Exception("Time making news is null.");
                else
                    this.time = value;
            }
        }

        /// <summary>
        /// Adding information.
        /// </summary>
        public String Content
        {
            get { return this.summary; }
            set { this.summary = value; }
        }

        /// <summary>
        /// Link to view detail news.
        /// </summary>
        public String Link
        {
            get { return this.link; }
            set { this.link = value; }
        }
    }
}